package com.tdam2011.grupo06;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class SeleccionTelefono extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seleccion_telefono);
        
        ListView lv = (ListView) findViewById(R.id.list);
        TelefonoAdapter adapter = new TelefonoAdapter(obtenerNumeros());
        lv.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_seleccion_telefono, menu);
        return true;
    }
    
    private ArrayList<String> obtenerNumeros() {
        ArrayList<String> nrosTelefono = new ArrayList<String>();
             
        nrosTelefono.add("3513921539");
        nrosTelefono.add("3514696429");
        nrosTelefono.add("3510000000");
        
        return nrosTelefono;
      }

    class Holder{
    	TextView txtNroTelefono;
    }
    
    class TelefonoAdapter extends BaseAdapter{

    	private ArrayList<String> _telefonos;
    	private LayoutInflater _inflater;
    	
    	public TelefonoAdapter(ArrayList<String> nrosTelefono){
			_telefonos = nrosTelefono;
			_inflater = LayoutInflater.from(SeleccionTelefono.this);
		}
    	
		public int getCount() {
			// TODO Auto-generated method stub
			return _telefonos.size();
		}

		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return _telefonos.get(position);
		}

		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			Holder holder = null;
			if (convertView == null) {
				convertView = _inflater.inflate(R.layout.telefono_item, null);
				holder = new Holder();
				
				holder.txtNroTelefono = (TextView) convertView
						.findViewById(R.id.textView1);
				
				convertView.setTag(holder);
			} else {
				holder = (Holder) convertView.getTag();
			}

			String nroTelefono = _telefonos.get(position);

			holder.txtNroTelefono.setText(nroTelefono);

			return convertView;
		}
    }
}
